﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
using System.Configuration;

/// <summary>
/// Summary description for cs_Mantain
/// </summary>
public class cs_Mantain
{
	public cs_Mantain()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public DataTable DT;
    //public cs_DataColnum.Register Register;
    public static ConnectionStringSettings PersonialConnString = WebConfigurationManager.ConnectionStrings["TwniceFoodConnectionString"];

    public static DataTable dt_Register(string UserName,string NickName,string Sex,string Password,string AgainPassword,string Email,string CellPhone,string BirthDay,string Constellation,string Favorite,DateTime RegisterDateTime)
    { 
      //public string UserName;
     // public string NickName;
     // public string Sex;
     // public string Password;
     // public string AgainPassword;
     // public string Email;
     // public string CellPhone;
     // public string BirthDay;
     // public string Constellation;
     // public string Favorite;
    //cs_DataColnum.Register Register=new cs_DataColnum.Register();
        cs_DataColnum.ParRegister ParRegister = new cs_DataColnum.ParRegister();
        SqlCommand sqlinsRegister = new SqlCommand();
        sqlinsRegister.CommandText="insert into Register (UserName,NickName,Sex,Password,AgainPassword,Email,CellPhone,BirthDay,Constellation,Favorite,RegisterDateTime)"+
            "values "+
            "(@UserName,@NickName,@Sex,@Password,@AgainPassword,@Email,@CellPhone,@BirthDay,@Constellation,@Favorite,@RegisterDateTime)";

        SqlConnection conn = new SqlConnection(PersonialConnString.ConnectionString);
        SqlCommand cmd = new SqlCommand(sqlinsRegister.CommandText, conn);
        conn.Open();
        try
        {
            ParRegister.UserName = new SqlParameter("@UserName", SqlDbType.NVarChar, 100);
            ParRegister.UserName.SqlDbType = SqlDbType.NVarChar;
            ParRegister.UserName.Value = UserName;
            cmd.Parameters.Add(ParRegister.UserName);

            ParRegister.NickName = new SqlParameter("@NickName", SqlDbType.NVarChar, 100);
            ParRegister.NickName.SqlDbType = SqlDbType.NVarChar;
            ParRegister.NickName.Value = NickName;
            cmd.Parameters.Add(ParRegister.NickName);

            ParRegister.Sex = new SqlParameter("@Sex", SqlDbType.NVarChar, 100);
            ParRegister.Sex.SqlDbType = SqlDbType.NVarChar;
            ParRegister.Sex.Value = Sex;
            cmd.Parameters.Add(ParRegister.Sex);

            ParRegister.Password = new SqlParameter("@Password", SqlDbType.NVarChar, 100);
            ParRegister.Password.SqlDbType = SqlDbType.NVarChar;
            ParRegister.Password.Value = Password;
            cmd.Parameters.Add(ParRegister.Password);

            ParRegister.AgainPassword = new SqlParameter("@AgainPassword", SqlDbType.NVarChar, 100);
            ParRegister.AgainPassword.SqlDbType = SqlDbType.NVarChar;
            ParRegister.AgainPassword.Value = AgainPassword;
            cmd.Parameters.Add(ParRegister.AgainPassword);

            ParRegister.Email = new SqlParameter("@Email", SqlDbType.NVarChar, 100);
            ParRegister.Email.SqlDbType = SqlDbType.NVarChar;
            ParRegister.Email.Value = Email;
            cmd.Parameters.Add(ParRegister.Email);

            ParRegister.CellPhone = new SqlParameter("@CellPhone", SqlDbType.NVarChar, 100);
            ParRegister.CellPhone.SqlDbType = SqlDbType.NVarChar;
            ParRegister.CellPhone.Value = CellPhone;
            cmd.Parameters.Add(ParRegister.CellPhone);

            ParRegister.BirthDay = new SqlParameter("@BirthDay", SqlDbType.NVarChar, 100);
            ParRegister.BirthDay.SqlDbType = SqlDbType.NVarChar;
            ParRegister.BirthDay.Value = BirthDay;
            cmd.Parameters.Add(ParRegister.BirthDay);

            ParRegister.Constellation = new SqlParameter("@Constellation", SqlDbType.NVarChar, 30);
            ParRegister.Constellation.SqlDbType = SqlDbType.NVarChar;
            ParRegister.Constellation.Value = Constellation;
            cmd.Parameters.Add(ParRegister.Constellation);

            ParRegister.Favorite = new SqlParameter("@Favorite", SqlDbType.NVarChar, 100);
            ParRegister.Favorite.SqlDbType = SqlDbType.NVarChar;
            ParRegister.Favorite.Value = Favorite;
            cmd.Parameters.Add(ParRegister.Favorite);

            ParRegister.RegisterDateTime = new SqlParameter("@RegisterDateTime", SqlDbType.DateTime);
            ParRegister.RegisterDateTime.SqlDbType = SqlDbType.DateTime;
            ParRegister.RegisterDateTime.Value = DateTime.Now;
            cmd.Parameters.Add(ParRegister.RegisterDateTime);
          
            
        }
        catch (SqlException ex)
        {
            ex.ToString();
        }   
            DataTable dt = new DataTable();
            dt.Load(cmd.ExecuteReader());
            return dt;

         
            conn.Close();
            conn.Dispose();
            cmd.Dispose();
        
       
    }
}